--- %%NOBANNER%% -->
/*-------------------<-- Start of Description -->--------------------\
| Generate random variate from a normal distribution |
|--------------------<--- End of Description -->---------------------|
|--------------------------------------------------------------------|
|--------------<--- Start of Files or Arguments Needed -->-----------|
| Arguments Need: |
| seed - seed; Required, default is the current system time; |
| var - the variable to save the generated random variates; |
| mean - the mean of the normal distribution; |
| std - the std of the distribution; |
| temp - the temporary variable to update the seed; |
| default is _rannor0_; |
|---------------<--- End of Files or Arguments Needed -->------------|
|--------------------------------------------------------------------|
|----------------<--- Start of Example and Usage -->-----------------|
|Example |
| data one; |
| do i=1 to 20; |
| x=%_rannor(mean=2, std=1); |
| %_rannor(seed=12345,var=y, mean=2, std=1); |
| output; |
| end; |
| run; %print(one); |
|Usage: %_rannor(seed=%sysfunc(datetime(), 15.), var=, mean=, std=, |
| temp=_rannor0_); |
\-------------------<--- End of Example and Usage -->---------------*/
%macro _rannor(seed=%sysfunc(datetime(), 15.), var=, mean=, std=,
temp=_rannor0_);
/*--------------------------------------------\
| Author: Duo Zhou; |
| Created: 3-22-2002 6:30pm; |
| Purpose: Random Normal Generator; |
\--------------------------------------------*/
%if (%quote(&seed) eq) %then %do;
%put ==> Error: This is not a valid seed!;
%if (%length(&var)) %then %do; &var=.; %end;
%else %do; .;%end;
%goto finish;
%end;
%else %do;
%if (%length(&var)) %then %do;
%if (not %sysfunc(rxmatch(%sysfunc(rxparse(_|.|$a|$A|$w)),&seed))) %then %do;
drop &temp;
retain &temp &seed;
%let seed=&temp;
%end;
call rannor(&seed, &var);
%if (%length(&mean.&std)) %then &var=&var;
%end;
%else rannor(&seed);
%if (%length(&std)) %then *&std;
%if (%length(&mean)) %then +&mean;
%end;
%finish:
%mend _rannor;